﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QH_MSS_WPF_Core.Utils
{
    public class FileWrite
    {
        public static void WriteFile(String str, string op)
        {
            var path = @$"C://QH//报警日志//{op}";
            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
            //
            DateTime dateTime = DateTime.Now;
            StreamWriter sw = new StreamWriter(@$"C://QH//报警日志//{op}//AlarmsHistory-{dateTime:yyyyMMdd}.txt", true, System.Text.Encoding.Default);
            sw.WriteLine(str);
            sw.Close();
        }
        public static void CleanFile(int days, string op)
        {
            string path = @$"C://QH//报警日志//{op}";
            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
            DirectoryInfo dir = new DirectoryInfo(path);
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                if (file.LastWriteTime < DateTime.Now.AddDays(-days))
                {
                    file.Delete();
                }
            }
        }

    }
}
